import dotenv from 'dotenv'
import mysql from 'mysql2/promise'

dotenv.config();

const pool = mysql.createPool({
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  waitForConnections: true, // 连接池满时等待（而非报错）
  connectionLimit: 10,      // 最大连接数
  queueLimit: 0             // 等待队列无限制
});

async function testConnection(){
    try {
        const connection =await pool.getConnection();
        console.log('数据库连接成功');
        connection.release();
    } catch (error) {
        console.error('数据库连接失败：', err.message);
    }
}

testConnection();

export default pool;